package com.model.math;

/**
 * 二维点类
 * 用于表示经纬度坐标或平面坐标
 */
public class Point2D {
    public double x;  // x坐标或经度
    public double y;  // y坐标或纬度

    /**
     * 构造函数
     * @param x x坐标或经度
     * @param y y坐标或纬度
     */
    public Point2D(double x, double y) {
        this.x = x;
        this.y = y;
    }

    /**
     * 从局部坐标创建Point2D
     */
    public static Point2D fromLocalCoordinates(double x, double y) {
        return new Point2D(x, y);
    }

    /**
     * 从经纬度创建Point2D
     */
    public static Point2D fromLatLon(double longitude, double latitude) {
        return new Point2D(longitude, latitude);
    }

    /**
     * 计算到另一个点的距离
     */
    public double distanceTo(Point2D other) {
        double dx = this.x - other.x;
        double dy = this.y - other.y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    /**
     * 创建点的副本
     */
    public Point2D clone() {
        return new Point2D(x, y);
    }

    @Override
    public String toString() {
        return String.format("Point2D(%.6f, %.6f)", x, y);
    }
} 